﻿#if UNITY_EDITOR
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace UFrame
{
    public class SpriteAssetPostprocessor : AssetPostprocessor
    {
        public static Dictionary<string, string> pathList = new Dictionary<string, string>();

        [MenuItem("Plateface/2D/设置批量路径Sprite")]
        public static void EditTexture()
        {
            var targetObj = Selection.activeObject; //这个函数可以得到你选中的对象
            if (targetObj && targetObj is Texture)
            {
                string path = AssetDatabase.GetAssetPath(targetObj);
                TextureImporter texture = AssetImporter.GetAtPath(path) as TextureImporter;
                texture.textureType = TextureImporterType.Sprite;
                texture.spritePixelsPerUnit = 1;
                texture.filterMode = FilterMode.Trilinear;
                texture.mipmapEnabled = false;
                TextureImporterPlatformSettings s = new TextureImporterPlatformSettings();
                s.textureCompression = TextureImporterCompression.Uncompressed;
                s.format = TextureImporterFormat.ARGB32;
                texture.SetPlatformTextureSettings(s);
                AssetDatabase.ImportAsset(path);

                //texture.spriteImportMode = SpriteImportMode.Multiple;
            }
        }

        void OnPreprocessAsset()
        {
        }

        void OnPreprocessTexture()
        {
            //比如路径Assets/bawAsset/Texture/Sprite/矢量.jpg
            string path = assetImporter.assetPath;

            foreach (var item in pathList.Values)
            {
                if (path.StartsWith(item))
                {
                    TextureImporter texImpoter = assetImporter as TextureImporter;
                    texImpoter.textureType = TextureImporterType.Sprite;
                    break;
                }
            }
        }
    }
}
#endif